package com.yupi.yoj.model.dto.comment;

import com.yupi.yoj.common.ErrorCode;
import com.yupi.yoj.exception.ThrowUtils;
import com.yupi.yoj.model.entity.Comment;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.*;

import java.util.Date;

@Data
@Document(indexName = "comment_v1")
public class CommentEsDTO {

    @Id
    private Long id;

    @Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_smart")
    private String content;

    @Field(type = FieldType.Integer)
    private Integer thumbNum;

    @Field(type = FieldType.Integer)
    private Integer favourNum;

    @Field(type = FieldType.Long)
    private Long userId;

    @Field(type = FieldType.Long)
    private Long questionId;

    @Field(type = FieldType.Date)
    private Date createTime;

    @Field(type = FieldType.Date)
    private Date updateTime;

    @Field(type = FieldType.Keyword)
    private String isDelete;

    // Getters and setters

    public static CommentEsDTO objToDto(Comment comment) {
        ThrowUtils.throwIf(null == comment, ErrorCode.PARAMS_ERROR, "评论不存在");
        CommentEsDTO commentEsDTO = new CommentEsDTO();
        BeanUtils.copyProperties(comment, commentEsDTO);
        return commentEsDTO;
    }
}